package io.renren.modules.miniapp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.utils.R;
import io.renren.modules.communityService.dto.MiniAppElectronicAccessCertificateGetDTO;
import io.renren.modules.communityService.entity.DbDailyHealthCardEntity;
import io.renren.modules.communityService.service.DbDailyHealthCardService;
import io.renren.modules.communityService.vo.MiniAppElectronicAccessCertificateGetVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.awt.*;


/**
 * 一键报警
 *
 * @author chenweilong
 * @email 1433471850@qq.com
 * @date 2021-03-21 13:45:49
 */
@RestController
@RequestMapping("miniapp/electronicaccesscertificate")
@Api(value = "电子出入证",tags = "电子出入证")
public class MiniAppElectronicAccessCertificateController {

    @Autowired
    private DbDailyHealthCardService dbDailyHealthCardService;

    /**
     * 列表
     */
    @GetMapping("/get")
    @ApiOperation(value = "获取电子出入证",notes = "获取电子出入证")
    public R list(MiniAppElectronicAccessCertificateGetDTO dto){
        MiniAppElectronicAccessCertificateGetVO vo = new MiniAppElectronicAccessCertificateGetVO();
        vo.setUserId(dto.getUserId());
        vo.setUserNickname(dto.getUserNickname());
        vo.setColor(Color.green.getRGB());
        //如果去过外地 健康码变黄色
        int count = dbDailyHealthCardService.count(new QueryWrapper<DbDailyHealthCardEntity>().lambda()
                .eq(DbDailyHealthCardEntity::getWhetherYouContactHubei,"是")
                .eq(DbDailyHealthCardEntity::getUserId,dto.getUserId())
        );
        if (count > 0) {
            vo.setColor(Color.yellow.getRGB());
        }
        //如果是高风险 健康码变红色
        int count1 = dbDailyHealthCardService.count(new QueryWrapper<DbDailyHealthCardEntity>().lambda()
                .eq(DbDailyHealthCardEntity::getReturnHighRisk,2)
                .eq(DbDailyHealthCardEntity::getUserId,dto.getUserId())
        );

        if (count1 > 0) {
            vo.setColor(Color.red.getRGB());
        }

        return R.data(vo);
    }


}
